package net.j4love.protobuf.service;

import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author He Peng
 * @create 2018-05-13 0:37
 * @update 2018-05-13 0:37
 * @updatedesc : 更新说明
 * @see
 */
public class TimeServiceImpl implements TimeServiceWrapper.TimeService.Interface {

    private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
    private static final DateFormat DATE_FORMAT = new SimpleDateFormat(DEFAULT_FORMAT);

    @Override
    public void time(RpcController controller,
                     TimeServiceWrapper.TimeRequest request,
                     RpcCallback<TimeServiceWrapper.TimeResponse> done) {
        String formatedTime = DATE_FORMAT.format(new Date()).toString();
        TimeServiceWrapper.TimeResponse timeResponse = TimeServiceWrapper.TimeResponse.newBuilder()
                .setTime("Service Response ->" + formatedTime).build();
        done.run(timeResponse);
    }
}
